<script setup>
/* 主窗口内容 */
import MainBar from "@/views/MainBar.vue"
import Updater from '@/views/Updater.vue'
import {Process} from '@/utils/ipcRenderer'
import {appReloadSymbol, appMainBarChange} from '@/utils/provideKey'
import {debounce} from '@/utils/func'

//更改标题栏状态
const titleBarOptions = reactive({
  logoShow: true,
  refreshShow: true,
  settingShow: true,
  notifyShow: true,
  accountShow: true
})
const titleBarChange = (func, cxt = null) => {
  if (typeof func !== 'function') {
    throw Error('The argument func must be a function.')
  }
  func.call(cxt, titleBarOptions)
}
//是否展示更新组件
const curWinKey = Process.env.EE_WINDOW_KEY
const createUpdater = ['main', 'conf'].includes(curWinKey)
//是否刷新当前页面
const isShowPageContent = ref(true)
const appReload = debounce(async () => {
  isShowPageContent.value = false
  await nextTick()
  isShowPageContent.value = true
})
//提供依赖
provide(appReloadSymbol, appReload)
provide(appMainBarChange, titleBarChange)
</script>

<template>
  <!--主导航栏-->
  <MainBar v-if="$route.meta.includeMainBar" :options="titleBarOptions"/>
  <div class="content" v-if="isShowPageContent">
    <!--路由视图-->
    <router-view name="default" v-slot="{ Component }">
      <div :class="$route.meta.includeMainBar ? 'ee-main-layout' : 'ee-partial-layout'">
        <component :is="Component"/>
      </div>
    </router-view>
  </div>
  <!--下载器下载进度-->
  <Updater v-if="createUpdater"/>
</template>

<style lang="less" scoped>
.content {
  width: 100%;
  height: 100%;
}

</style>
